package com.ecoolex.ying.space.core.service;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ecoolex.framework.common.enums.ResultCode;
import com.ecoolex.framework.common.exception.BizException;
import com.ecoolex.framework.common.util.BizAssert;
import com.ecoolex.ying.space.core.manager.PaymentOrderManager;
import com.ecoolex.ying.space.entity.EstateProjectActivityCouponOrder;
import com.ecoolex.ying.space.entity.EstateProjectActivityCouponPackage;
import com.ecoolex.ying.space.enums.EstateProjectActivityCouponOrderStatus;
import com.ecoolex.ying.space.enums.EstateProjectActivityCouponPackageStatus;

@Service
public class WeiXinPayService {
	
	@Autowired
    private PaymentOrderManager paymentOrderManager;
	
	public Map payApply(EstateProjectActivityCouponOrder order, String ipAdress, String createUser) {
		BizAssert.isTrue(EstateProjectActivityCouponOrderStatus.canPay(order),ResultCode.VERIFY.build(10), "订单必须在待支付状态下才能发起支付");
		return paymentOrderManager.paymentApply(order, ipAdress, createUser);
	}

	public String orderNotify(String body, String createUser) {
		return paymentOrderManager.orderNotify(body, createUser);
	}
	
	public boolean weixinRefundApply(EstateProjectActivityCouponOrder order,EstateProjectActivityCouponPackage couponPackage, String createUser) throws BizException {
		BizAssert.isTrue(EstateProjectActivityCouponOrderStatus.canRefund(order),ResultCode.VERIFY.build(10), "订单必须在已支付状态下才能发起退款");
		BizAssert.isTrue(EstateProjectActivityCouponPackageStatus.canRefund(couponPackage),ResultCode.VERIFY.build(11), "用户代金券必须在待使用或已过期状态下才能发起退款");
		return paymentOrderManager.refundApply(order, createUser);
	}
	
	public String refundNotify(String body, String createUser) {
		return paymentOrderManager.refundNotify(body, createUser);
	}
}
